/**
 * 获取(指定/当前)YYYY-MM-dd HH:mm:ss格式时间
 * @param {String} Arg_Datetime
 * @returns
 */
function DateTime(Arg_Datetime) {
	if(Arg_Datetime&&Arg_Datetime.includes('-')){
		Arg_Datetime = Arg_Datetime.replace(/-/g, "/").substring(0,19);
	}
	const times = Arg_Datetime ? new Date(Arg_Datetime) : new Date();
	let year = times.getFullYear();
	let month = times.getMonth() + 1;
	let days = times.getDate();
	let hour = times.getHours()
	let minutes = times.getMinutes()
	let second = times.getSeconds()
	month = month < 10 ? '0' + month : month;
	days = days < 10 ? '0' + days : days;
	hour = hour < 10 ? '0' + hour : hour;
	minutes = minutes < 10 ? '0' + minutes : minutes;
	second = second < 10 ? '0' + second : second;
	return year + '-' + month + '-' + days + ' ' + hour + ':' + minutes + ':' + second;
}

/**
 * 获取当前时间戳，单位秒
 * @returns
 */
function getCurrentTimestamp() {
	return Math.floor(Date.now() / 1000);
}

function getCountDown(date){
	if(date&&date.includes('-')){
		date = date.replace(/-/g, "/").substring(0,19);
	}
	let now=new Date();
	let future=new Date(date)//距离的时间
	let index=(future-now)/1000/(60*60*24)
	let day=parseInt(index)//天
	let h=parseInt((index-day)*24)//时
	let m=parseInt((index-day-h/24)*24*60)//分
	let s=parseInt((index-day-h/24-m/60/24)*24*60*60)//秒
	return {day,h,m,s}
}

module.exports = {
	DateTime,
	getCurrentTimestamp,
	getCountDown
}